import { Sprite } from "cc";
import { Global } from "../../Global";
import { Entity } from "../def/Entity";
import { Conversation } from "./def/Conversation";
import { NPC } from "./def/NPC";

export class AngelNPC extends NPC {

    private conversations: any[] = [
        {
            speak: 'npc',
            caption: '勇士你好，你决定要进入地下城吗？',
        },
        {
            speak: 'hero',
            caption: '是的！'
        },
        {
            speak: 'npc',
            caption: '那一定记住这些重要的信息。'
        },
        {
            speak: 'npc',
            caption: '大剑在第四层，盔甲在第六层。'
        },
        {
            speak: 'npc',
            caption: '先拿到装备再去战斗吧。'
        },
        {
            speak: 'hero',
            caption: '我知道了，让我进入地下城吧。'
        },
        {
            speak: 'npc',
            caption: '我这有一把钥匙，打开门就可以进入地下城。'
        },
        {
            speak: 'npc',
            caption: '穿过护城河就没有退路了，加油吧勇士！'
        }
    ]

    private state: string = 'init'

    startConversation() {
        Global.convManage.startConversation(this.buildConv(), () => {
            this.state = 'finish'
            Global.em.removeEntity(Global.fm.getFloor(), this)
            Global.hero._heroState.keys.yellow += 1
            Global.popUtil.popUp('你获得了一把钥匙！')
        })
    }

    buildConv() {
        const result = []
        this.conversations.forEach(conv => {
            result.push({
                role: conv.speak === 'hero' ? 'hero' : this.type,
                avator: conv.speak === 'hero' ? Global.heroManage.getDownSF() : this.node.getComponent(Sprite).spriteFrame,
                caption: conv.caption
            })
        })
        return result
    }
}